home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_1199 / 1795 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  6.6 KB

  1. From: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
  2. Date: Mon, 1 Aug 94 11:12:50 +0200
  3. Message-Id: <9408010912.AA29594@issan.informatik.uni-dortmund.de>
  4. To: mint@atari.archive.umich.edu
  5. Subject: Improved pipefs (update)
  6.  
  7. This is a update of the patches to improve the pipefs.  I have
  8. disabled Juergen's changes to pipe_write and pipe_read, since they
  9. don't compile any more (sorry, Juergen), and i think it is wrong to
  10. check for TS_HOLD there, it's an unclean mixing of different tty
  11. layers.  Use pagers!
  12.  
  13. IMHO this is much cleaner and simpler, but i may be biased :-).
  14.  
  15. --- pipefs.c~    Sat Jul 30 20:02:16 1994
  16. +++ pipefs.c    Sat Jul 30 20:17:42 1994
  17. @@ -82,10 +82,10 @@
  18.  struct pipe {
  19.      int    readers;    /* number of readers of this pipe */
  20.      int    writers;    /* number of writers of this pipe */
  21. -    int    head, tail;    /* pipe head, tail (head == tail for empty) */
  22. +    int    start, len;    /* pipe head index, size */
  23.      long    rsel;        /* process that did select() for reads */
  24.      long    wsel;        /* process that did select() for writes */
  25. -    char    buf[PIPESIZ+4];    /* pipe data */
  26. +    char    buf[PIPESIZ];    /* pipe data */
  27.  };
  28.  
  29.  struct fifo {
  30. @@ -476,11 +476,11 @@
  31.      } else tty = 0;
  32.  
  33.  /* set up the pipes appropriately */
  34. -    inp->head = inp->tail = 0;
  35. +    inp->start = inp->len = 0;
  36.      inp->readers = selfread ? 1 : VIRGIN_PIPE; inp->writers = 1;
  37.      inp->rsel = inp->wsel = 0;
  38.      if (outp) {
  39. -        outp->head = outp->tail = 0;
  40. +        outp->start = outp->len = 0;
  41.          outp->readers = 1; outp->writers = selfread ? 1 : VIRGIN_PIPE;
  42.          outp->wsel = outp->rsel = 0;
  43.      }
  44. @@ -598,7 +598,7 @@
  45.  pipe_write(f, buf, nbytes)
  46.      FILEPTR *f; const char *buf; long nbytes;
  47.  {
  48. -    int ptail, phead, j;
  49. +    int plen, j;
  50.      char *pbuf;
  51.      struct pipe *p;
  52.      struct fifo *this;
  53. @@ -621,9 +621,7 @@
  54.              sleep (IO_Q, (long)&this->tty->state);
  55.              goto check_atomicity;
  56.          }
  57. -        r = p->tail - p->head;
  58. -        if (r < 0) r += PIPESIZ+4;
  59. -        r = PIPESIZ - r; /* r is the number of bytes we can write */
  60. +        r = PIPESIZ - p->len; /* r is the number of bytes we can write */
  61.          if (r < nbytes) {
  62.      /* check for broken pipes */
  63.              if (p->readers == 0 || p->readers == VIRGIN_PIPE) {
  64. @@ -643,11 +641,9 @@
  65.      }
  66.  
  67.      while (nbytes > 0) {
  68. -        ptail = p->tail; phead = p->head;
  69. -        j = ptail+4;
  70. -        if (j >= PIPESIZ+4) j -= PIPESIZ+4;
  71. -        if (j != phead) {
  72. -#if 1
  73. +        plen = p->len;
  74. +        if (plen < PIPESIZ) {
  75. +#if 0 /* does not compile any more */
  76.              int free, wrap;
  77.  
  78.              if (is_terminal(f) && !(f->flags & O_HEAD) &&
  79. @@ -692,18 +688,26 @@
  80.                  buf += free;
  81.              }
  82.  #else
  83. -            j -= 3;
  84. -            pbuf = &p->buf[ptail];
  85. -            do {
  86. -                *pbuf++ = *buf++;
  87. -                nbytes--; bytes_written++;
  88. -                if ( (ptail = j) == 0 )
  89. -                    pbuf = &p->buf[0];
  90. -                j++;
  91. -                if (j >= PIPESIZ+4) j = 0;
  92. -            } while ( (nbytes > 0) && (j != phead) );
  93. +            pbuf = &p->buf[(p->start + plen) & (PIPESIZ - 1)];
  94. +            /* j is the amount that can be written continuously */
  95. +            j = PIPESIZ - (pbuf - p->buf);
  96. +            if (j > nbytes) j = nbytes;
  97. +            if (j > PIPESIZ - plen) j = PIPESIZ - plen;
  98. +            nbytes -= j; plen += j;
  99. +            bytes_written += j;
  100. +            memcpy (pbuf, buf, j);
  101. +            buf += j;
  102. +            if (nbytes > 0 && plen < PIPESIZ)
  103. +              {
  104. +                j = PIPESIZ - plen;
  105. +                if (j > nbytes) j = nbytes;
  106. +                nbytes -= j; plen += j;
  107. +                bytes_written += j;
  108. +                memcpy (p->buf, buf, j);
  109. +                buf += j;
  110. +              }
  111. +            p->len = plen;
  112.  #endif
  113. -            p->tail = ptail;
  114.          } else {        /* pipe full */
  115.              if (p->readers == 0 || p->readers == VIRGIN_PIPE) {
  116.              /* maybe some other signal is waiting for us? */
  117. @@ -740,7 +744,7 @@
  118.  pipe_read(f, buf, nbytes)
  119.      FILEPTR *f; char *buf; long nbytes;
  120.  {
  121. -    int phead, ptail;
  122. +    int plen, j;
  123.      struct fifo *this;
  124.      struct pipe *p;
  125.      long bytes_read = 0;
  126. @@ -754,9 +758,9 @@
  127.      }
  128.  
  129.      while (nbytes > 0) {
  130. -        phead = p->head; ptail = p->tail;
  131. -        if (ptail != phead) {
  132. -#if 1
  133. +        plen = p->len;
  134. +        if (plen > 0) {
  135. +#if 0 /* does not compile any more */
  136.              int left, wrap;
  137.  
  138.              pbuf = p->buf + phead;
  139. @@ -794,18 +798,30 @@
  140.                  buf += left;
  141.              }
  142.  #else
  143. -            pbuf = &p->buf[phead];
  144. -            do {
  145. -                *buf++ = *pbuf++;
  146. -                nbytes--; bytes_read++;
  147. -                phead++;
  148. -                if (phead >= PIPESIZ+4) {
  149. -                    phead = 0;
  150. -                    pbuf = &p->buf[phead];
  151. -                }
  152. -            } while ( (nbytes > 0) && (phead != ptail) );
  153. +            pbuf = &p->buf[p->start];
  154. +            /* j is the amount that can be read continuously */
  155. +            j = PIPESIZ - p->start;
  156. +            if (j > nbytes) j = nbytes;
  157. +            if (j > plen) j = plen;
  158. +            nbytes -= j; plen -= j;
  159. +            bytes_read += j;
  160. +            p->start += j;
  161. +            memcpy (buf, pbuf, j);
  162. +            buf += j;
  163. +            if (nbytes > 0 && plen > 0)
  164. +              {
  165. +                j = plen;
  166. +                if (j > nbytes) j = nbytes;
  167. +                nbytes -= j; plen -= j;
  168. +                bytes_read += j;
  169. +                p->start = j;
  170. +                memcpy (buf, p->buf, j);
  171. +                buf += j;
  172. +              }
  173. +            p->len = plen;
  174. +            if (plen == 0 || p->start == PIPESIZ)
  175. +              p->start = 0;
  176.  #endif
  177. -            p->head = phead;
  178.          }
  179.          else if (p->writers <= 0 || p->writers == VIRGIN_PIPE) {
  180.              TRACE(("pipe_read: no more writers"));
  181. @@ -912,8 +928,7 @@
  182.                  DEBUG(("pipe FIONREAD: no writers yet"));
  183.                  r = -1;
  184.              } else {
  185. -                r = p->tail - p->head;
  186. -                if (r < 0) r += PIPESIZ+4;
  187. +                r = p->len;
  188.                  if (is_terminal(f)) {
  189.                      if (!(f->flags & O_HEAD))
  190.                          r = r >> 2;    /* r /= 4 */
  191. @@ -933,9 +948,7 @@
  192.              if (p->readers <= 0) {
  193.                  r = -1;
  194.              } else {
  195. -                r = p->tail - p->head;
  196. -                if (r < 0) r += PIPESIZ+4;
  197. -                r = PIPESIZ - r;
  198. +                r = PIPESIZ - p->len;
  199.                  if (is_terminal(f)) {
  200.                      if (f->flags & O_HEAD)
  201.                          r = r >> 2;    /* r /= 4 */
  202. @@ -1002,11 +1015,11 @@
  203.              flushtype = *which;
  204.  
  205.          if ((flushtype & 1) && this->inp) {
  206. -            this->inp->head = this->inp->tail;
  207. +            this->inp->start = this->inp->len = 0;
  208.              wake(IO_Q, (long)this->inp);
  209.          }
  210.          if ((flushtype & 2) && this->outp) {
  211. -            this->outp->head = this->outp->tail;
  212. +            this->outp->start = this->outp->len = 0;
  213.              wake(IO_Q, (long)this->outp);
  214.          }
  215.          break;
  216. @@ -1017,8 +1030,7 @@
  217.              if (p->readers <= 0) {
  218.                  r = -1;
  219.              } else {
  220. -                r = p->tail - p->head;
  221. -                if (r < 0) r += PIPESIZ+4;
  222. +                r = p->len;
  223.                  if (is_terminal(f) && (f->flags & O_HEAD))
  224.                      r = r >> 2;    /* r /= 4 */
  225.              }
  226. @@ -1206,7 +1218,6 @@
  227.  {
  228.      struct fifo *this;
  229.      struct pipe *p;
  230. -    int j;
  231.  
  232.      this = (struct fifo *)f->fc.index;
  233.  
  234. @@ -1218,7 +1229,7 @@
  235.          }
  236.  
  237.  /* NOTE: if p->writers <= 0 then reads won't block (they'll fail) */
  238. -        if ((p->tail != p->head &&
  239. +        if ((p->len > 0 &&
  240.              (!is_terminal(f) || !(f->flags & O_HEAD) ||
  241.               !(this->tty->state & TS_HOLD))) ||
  242.              p->writers <= 0) {
  243. @@ -1237,9 +1248,7 @@
  244.              DEBUG(("write select on wrong end of pipe"));
  245.              return 0;
  246.          }
  247. -        j = p->tail+4;
  248. -        if (j >= PIPESIZ+4) j -= PIPESIZ+4;
  249. -        if ((j != p->head &&
  250. +        if (p->len < PIPESIZ &&
  251.              (!is_terminal(f) || (f->flags & O_HEAD) ||
  252.               !(this->tty->state & TS_HOLD))) ||
  253.              p->readers <= 0)
  254.